package vn.smartoffice.promail.controller.menu;

import java.util.HashMap;
import java.util.Map;

import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import org.zkoss.zul.Window;

import vn.smartoffice.auth.UserService;
import vn.smartoffice.promail.entity.MailContact;
import vn.smartoffice.promail.entity.MailContactGroup;

@VariableResolver(DelegatingVariableResolver.class)
public class MainMenuCtr {

	@WireVariable private UserService userService;

	private MailContactGroup currentGroup;

	public String getCurrentName() {
		return userService.getCurrentUser().getFirstName();
	}
	
	@Command("addNewMail")
	public void addNewMail() {
		Window window = (Window) Executions.createComponents("dialog/newMail.zul", null, null);
		window.doModal();
	}
	
	@Command("addContact")
	public void add() {
		MailContact selectedContact = new MailContact();
		selectedContact.setUser(userService.getCurrentUser());

		Map<String, Object> dataArgs = new HashMap<>();
		dataArgs.put("maiContact", selectedContact);
		dataArgs.put("currentGroup", currentGroup);
		Window window = (Window) Executions.createComponents("dialog/contact.zul", null, dataArgs);
		window.doModal();
	}

	@GlobalCommand
	public void loadCurrentGroupAdd(@BindingParam("groupSelected") MailContactGroup mailContactGroup) {
		this.currentGroup = mailContactGroup;
	}
}
